home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1810 / 1810.xpi / chrome / showcase.jar / content / bindings / tabbar.xml
Extensible Markup Language  |  2010-01-17  |  9KB  |  261 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  4. <!ENTITY % tabBrowserDTD SYSTEM "chrome://global/locale/tabbrowser.dtd" >
  5. %tabBrowserDTD;
  6. <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
  7. %globalDTD;
  8. <!ENTITY % overlayDTD SYSTEM "chrome://showcase/locale/overlay.dtd">
  9. %overlayDTD;
  10. ]>
  11.  
  12. <bindings id="tabBarBindings"
  13.           xmlns="http://www.mozilla.org/xbl"
  14.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  15.           xmlns:xbl="http://www.mozilla.org/xbl">
  16.   <!-- alltabs-popup binding
  17.        This binding relies on the structure of the tabbrowser binding.
  18.        Therefore it should only be used as a child of the tabs element.
  19.        This binding is exposed as a pseudo-public-API so themes can customize
  20.        the tabbar appearance without having to be scriptable
  21.        (see globalBindings.xml in Pinstripe for example).
  22.   -->
  23.   <binding id="tabbar-alltabs-popup"
  24.            extends="chrome://global/content/bindings/popup.xml#popup">
  25.     <implementation implements="nsIDOMEventListener">
  26.       <method name="_menuItemOnCommand">
  27.         <parameter name="aEvent"/>
  28.         <body><![CDATA[
  29.           // note, the tab may not be valid (if after we built the popup
  30.           // the tab was closed.  but selectedItem setter handles that
  31.           // gracefully.
  32.           var tabcontainer = getBrowser().mTabContainer;
  33.           tabcontainer.selectedItem = aEvent.target.tab;
  34.         ]]></body>
  35.       </method>
  36.  
  37.       <method name="_tabOnAttrModified">
  38.         <parameter name="aEvent"/>
  39.         <body><![CDATA[
  40.           var menuItem = aEvent.target.mCorrespondingMenuitem;
  41.           if (menuItem) {
  42.             var attrName = aEvent.attrName;
  43.             switch (attrName) {
  44.               case "label":
  45.               case "crop":
  46.               case "busy":
  47.               case "image":
  48.                 if (aEvent.attrChange == aEvent.REMOVAL)
  49.                   menuItem.removeAttribute(attrName);
  50.                 else
  51.                   menuItem.setAttribute(attrName, aEvent.newValue);
  52.             }
  53.           }
  54.         ]]></body>
  55.       </method>
  56.  
  57.       <method name="handleEvent">
  58.         <parameter name="aEvent"/>
  59.         <body><![CDATA[
  60.           if (!aEvent.isTrusted)
  61.             return;
  62.  
  63.           switch (aEvent.type) {
  64.             case "command":
  65.               this._menuItemOnCommand(aEvent);
  66.               break;
  67.             case "DOMAttrModified":
  68.               this._tabOnAttrModified(aEvent);
  69.           }
  70.         ]]></body>
  71.       </method>
  72.  
  73.       <method name="_onHidingAllTabsPopup">
  74.         <body><![CDATA[
  75.           // clear out the menu popup and remove the listeners
  76.           while (this.hasChildNodes()) {
  77.             var menuItem = this.lastChild;
  78.             menuItem.removeEventListener("command", this, false);
  79.             menuItem.tab.removeEventListener("DOMAttrModified", this, false);
  80.             menuItem.tab.mCorrespondingMenuitem = null;
  81.             this.removeChild(menuItem);
  82.           }
  83.         ]]></body>
  84.       </method>
  85.  
  86.       <method name="_onShowingAllTabsPopup">
  87.         <parameter name="aEvent"/>
  88.         <body><![CDATA[
  89.           // set up the menu popup
  90.           var tabcontainer = getBrowser().mTabContainer;
  91.           var tabs = tabcontainer.childNodes;
  92.  
  93.           for (var i = 0; i < tabs.length; i++) {
  94.             this._addTabToPopup(tabs[i]);
  95.           }
  96.         ]]></body>
  97.       </method>
  98.  
  99.       <method name="_addTabToPopup">
  100.         <parameter name="curTab"/>
  101.         <body><![CDATA[
  102.           var menuItem = document.createElementNS(
  103.             "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", 
  104.             "menuitem");
  105.  
  106.           if (curTab.selected)
  107.             menuItem.setAttribute("selected", "true");
  108.           menuItem.setAttribute("class", "menuitem-iconic alltabs-item");
  109.  
  110.           menuItem.setAttribute("label", curTab.label);
  111.           menuItem.setAttribute("crop", curTab.getAttribute("crop"));
  112.           menuItem.setAttribute("image", curTab.getAttribute("image"));
  113.           if (curTab.hasAttribute("busy"))
  114.             menuItem.setAttribute("busy", curTab.getAttribute("busy"));
  115.           if (curTab.linkedBrowser && curTab.linkedBrowser.contentDocument)
  116.             menuItem.setAttribute("tooltiptext", curTab.linkedBrowser.contentDocument.URL);
  117.  
  118.           // XXX todo
  119.           // statustext not working yet, since I don't have a menubar
  120.           // reuse the menubar statustext logic
  121.           var URI = curTab.linkedBrowser.currentURI.spec;
  122.           menuItem.setAttribute("statustext", URI);
  123.  
  124.           // Keep some attributes of the menuitem in sync with its
  125.           // corresponding tab (e.g. the tab label)
  126.           curTab.mCorrespondingMenuitem = menuItem;
  127.           curTab.addEventListener("DOMAttrModified", this, false);
  128.  
  129.           menuItem.tab = curTab;
  130.           menuItem.addEventListener("command", this, false);
  131.           this.appendChild(menuItem);
  132.         ]]></body>
  133.       </method>
  134.  
  135.     </implementation>
  136.     <handlers>
  137.       <handler event="popupshowing"><![CDATA[
  138.         if (event.target == this)
  139.           this._onShowingAllTabsPopup(event);
  140.       ]]></handler>
  141.       <handler event="popuphiding"><![CDATA[
  142.         if (event.target == this)
  143.           this._onHidingAllTabsPopup();
  144.       ]]></handler>
  145.     </handlers>
  146.   </binding>
  147.  
  148.   <binding id="tabbar-lefttabs-popup"
  149.            extends="chrome://showcase/content/bindings/tabbar.xml#tabbar-alltabs-popup">
  150.     <implementation>
  151.       <method name="_onShowingAllTabsPopup">
  152.         <parameter name="aEvent"/>
  153.         <body><![CDATA[
  154.           // set up the menu popup
  155.           var tabcontainer = getBrowser().mTabContainer;
  156.           var tabs = tabcontainer.childNodes;
  157.           var tabsLeft = ShowcaseCache.calculateHiddenTabsLeft();
  158.  
  159.           if (tabsLeft < 1) {
  160.             aEvent.preventDefault();
  161.             return;
  162.           }
  163.  
  164.           for (var i = tabsLeft - 1; i >= 0; i--) {
  165.             this._addTabToPopup(tabs[i]);
  166.           }
  167.         ]]></body>
  168.       </method>
  169.     </implementation>
  170.   </binding>
  171.  
  172.   <binding id="tabbar-righttabs-popup"
  173.            extends="chrome://showcase/content/bindings/tabbar.xml#tabbar-alltabs-popup">
  174.     <implementation>
  175.       <method name="_onShowingAllTabsPopup">
  176.         <parameter name="aEvent"/>
  177.         <body><![CDATA[
  178.           // set up the menu popup
  179.           var tabcontainer = getBrowser().mTabContainer;
  180.           var tabs = tabcontainer.childNodes;
  181.           var tabsRight = ShowcaseCache.calculateHiddenTabsRight();
  182.  
  183.           if (tabsRight < 1) {
  184.             aEvent.preventDefault();
  185.             return;
  186.           }
  187.  
  188.           for (var i = tabs.length - tabsRight; i < tabs.length; i++) {
  189.             this._addTabToPopup(tabs[i]);
  190.           }
  191.         ]]></body>
  192.       </method>
  193.     </implementation>
  194.   </binding>
  195.  
  196.   <binding id="left-tooltip"
  197.            extends="chrome://global/content/bindings/popup.xml#tooltip">
  198.     <implementation>
  199.       <field name="mStringBundle">
  200.         document.getElementById("bundle_showcaseoverlay")
  201.       </field>
  202.  
  203.       <method name="_onShowingLeftTooltip">
  204.         <body><![CDATA[
  205.           var tabsOnLeft = ShowcaseCache.calculateHiddenTabsLeft();
  206.           switch (tabsOnLeft) {
  207.             case 0:
  208.               this.setAttribute('label', this.mStringBundle.getString("showcaseNoTabsLeftTooltip"));
  209.               break;
  210.             case 1:
  211.               this.setAttribute('label', this.mStringBundle.getString("showcaseTabLeftTooltip"));
  212.               break;
  213.             default:
  214.               this.setAttribute('label', "" + tabsOnLeft + " " + this.mStringBundle.getString("showcaseTabsLeftTooltip"));
  215.               break;
  216.           }
  217.           return true;
  218.         ]]></body>
  219.       </method>
  220.  
  221.     </implementation>
  222.     <handlers>
  223.       <handler event="popupshowing"><![CDATA[
  224.         this._onShowingLeftTooltip();
  225.       ]]></handler>
  226.     </handlers>
  227.   </binding>
  228.  
  229.   <binding id="right-tooltip"
  230.            extends="chrome://global/content/bindings/popup.xml#tooltip">
  231.     <implementation>
  232.       <field name="mStringBundle">
  233.         document.getElementById("bundle_showcaseoverlay")
  234.       </field>
  235.  
  236.       <method name="_onShowingRightTooltip">
  237.         <body><![CDATA[
  238.           var tabsOnRight = ShowcaseCache.calculateHiddenTabsRight();
  239.           switch (tabsOnRight) {
  240.             case 0:
  241.               this.setAttribute('label', this.mStringBundle.getString("showcaseNoTabsRightTooltip"));
  242.               break;
  243.             case 1:
  244.               this.setAttribute('label', this.mStringBundle.getString("showcaseTabRightTooltip"));
  245.               break;
  246.             default:
  247.               this.setAttribute('label', "" + tabsOnRight + " " + this.mStringBundle.getString("showcaseTabsRightTooltip"));
  248.               break;
  249.           }
  250.           return true;
  251.         ]]></body>
  252.       </method>
  253.  
  254.     </implementation>
  255.     <handlers>
  256.       <handler event="popupshowing"><![CDATA[
  257.         this._onShowingRightTooltip();
  258.       ]]></handler>
  259.     </handlers>
  260.   </binding>
  261. </bindings>